import React, { PureComponent, Fragment } from 'react';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Table, Button, Input, message, Radio, Checkbox, DatePicker, Tooltip, InputNumber, Col, Select, Row, Card, Modal, Divider } from 'antd';
import PmsBuildStyle from '../../../PortfolioManagement/PmsBuild.less';
import { generateSelect, showValue } from '../../../PortfolioManagement/utils';
import moment from 'moment';

const { TextArea } = Input;
const FormItem = Form.Item;
const { Option } = Select;
const { confirm } = Modal;
@Form.create()
export default class InverstMent extends PureComponent {
  state = {
    isValidity: false,
    occupationDays: 0,
    expireAmount: 0,
    reactValue: '0',
    reactValue2: '0',
    companyValue: 'Y',
    twocycleDValue: '',
    istwocycleY: true,
    isDis: true,
  };

  componentDidMount() {
    const {
      that,
      toolInfo,
      dictMap,
      type,
      user: { currentUser },
      form: { getFieldsValue, getFieldDecorator, validateFieldsAndScroll },
    } = this.props;

    const { isValidity } = this.state;
    const userId = localStorage.getItem('antd-pro-userId');

    let itemTool = toolInfo;
    if (!itemTool) {
      itemTool = {};
    }

    if (itemTool.validityType) {
      this.onChangeValidityType(itemTool.validityType);
    }
  }

  onChangeValidityType = (e) => {
    const {
      form: { setFieldsValue },
    } = this.props;

    setFieldsValue({
      validitydt: undefined,
    });

    //2','区间有效
    let isValidity = true;
    //1','长期有效
    if ('1' === e) {
      isValidity = false;
    }

    this.setState({
      isValidity,
    });
  };

  render() {
    const {
      that,
      toolInfo,
      dictMap,
      type,
      status,
      user: { currentUser },
      form: { getFieldsValue, getFieldDecorator, validateFieldsAndScroll },
    } = this.props;

    const { isValidity } = this.state;
    const userId = localStorage.getItem('antd-pro-userId');

    let itemTool = toolInfo;
    if (!itemTool) {
      itemTool = {};
    }

    let dis = false;
    if (type === 'view') {
      dis = true;
    }
    return (
      <Form onSubmit={this.handleSearch} layout='inline'>
        <div>
          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
            <Col style={{ display: 'none' }}>
              <FormItem label='id'>
                {getFieldDecorator('id', {
                  initialValue: itemTool.id ? itemTool.id : '',
                })(<Input placeholder='请输入' />)}
              </FormItem>
            </Col>

            <Col md={12} sm={12}>
              <FormItem label='标题'>
                {getFieldDecorator('title', {
                  initialValue: itemTool.title ? itemTool.title : '',
                  rules: [
                    {
                      required: true,
                      message: '请输入标题',
                    },
                  ],
                })(<Input placeholder='请输入' disabled={dis} />)}
              </FormItem>
            </Col>
            <Col md={12} sm={12}>
              <FormItem label='重要性'>
                {getFieldDecorator('type', {
                  initialValue: status ? status : null,
                  rules: [
                    {
                      required: true,
                      message: '请输入重要性',
                    },
                  ],
                })(
                  <Select style={{ width: '100%' }} disabled={dis} placeholder='请选择'>
                    {generateSelect('LOCAL_MSG_TYPE', dictMap)}
                  </Select>,
                )}
              </FormItem>
            </Col>
          </Row>
          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
            <Col md={12} sm={12}>
              <FormItem label='推送时间'>
                {getFieldDecorator('targetdt', {
                  initialValue: itemTool.targetdt ? moment(itemTool.targetdt) : moment(),
                  rules: [
                    {
                      required: true,
                      message: '请选择推送时间',
                    },
                  ],
                })(<DatePicker style={{ width: '100%' }} placeholder='' disabled={dis} />)}
              </FormItem>
            </Col>
            <Col md={12} sm={12}>
              <FormItem label='推送人'>
                {getFieldDecorator('creator', {
                  initialValue: itemTool.creator ? itemTool.creator + '-' + itemTool.creatorName : userId + '-' + currentUser.name,
                  rules: [
                    {
                      required: true,
                      message: '请输入推送人',
                    },
                  ],
                })(<Input placeholder='请输入' disabled />)}
              </FormItem>
            </Col>
          </Row>
          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
            <Col md={12} sm={12}>
              <FormItem label='有效期类型'>
                {getFieldDecorator('validityType', {
                  initialValue: itemTool.validityType ? itemTool.validityType : '',
                  rules: [
                    {
                      required: true,
                      message: '请输入有效期类型',
                    },
                  ],
                })(
                  <Select style={{ width: '100%' }} disabled={dis} placeholder='请选择'>
                    {generateSelect('LOCAL_MSG_VALIDITYTYPE', dictMap)}
                  </Select>,
                )}
              </FormItem>
            </Col>

            {isValidity ? (
              <Col md={12} sm={12}>
                <FormItem label='有效截止日期'>
                  {getFieldDecorator('validitydt', {
                    initialValue: itemTool.validitydt ? moment(itemTool.validitydt, 'YYYY-MM-DD') : undefined,
                    rules: [
                      {
                        required: true,
                        message: '请输入有效截止日期',
                      },
                    ],
                  })(<DatePicker style={{ width: '100%' }} placeholder='' disabled={dis} />)}
                </FormItem>
              </Col>
            ) : (
              ''
            )}
          </Row>
          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
            <Col md={24} sm={32}>
              <FormItem label='内容'>
                {getFieldDecorator('content', {
                  initialValue: itemTool.content ? itemTool.content : '',
                })(<TextArea disabled={dis} />)}
              </FormItem>
            </Col>
          </Row>
        </div>
      </Form>
    );
  }
}
